/**
 * @param {number[][]} triangle
 * @return {number}
 */
var minimumTotal = function (triangle) {
  let m = triangle.length
  if (m === 0) return 0
  let dp = new Array(m).fill(0)
  for (let i = 0; i < m; i++) {
    let n = triangle[i].length
    dp[i] = new Array(n).fill(0)
  } // 生成二维数组
  for (let i = m - 1; i >= 0; i--) {
    for (let j = 0; j < dp[i].length; j++) {
      if (i == m - 1) {
        dp[i][j] = triangle[i][j]
      } else {
        dp[i][j] = Math.min(dp[i + 1][j], dp[i + 1][j + 1]) + triangle[i][j]
      }
    }
  }
  return dp[0][0]
};
minimumTotal([[2], [3, 4], [6, 5, 7], [4, 1, 8, 3]])